package cn.iocoder.yudao.module.system.service.curingemperature;

import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;

import java.util.*;
import cn.iocoder.yudao.module.system.controller.admin.curingemperature.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.curingemperature.CuringEmperatureDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;

import cn.iocoder.yudao.module.system.dal.mysql.curingemperature.CuringEmperatureMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;

/**
 * 固化温度 Service 实现类
 *
 * @author 超级管理员
 */
@Service
@Validated
public class CuringEmperatureServiceImpl implements CuringEmperatureService {

    @Resource
    private CuringEmperatureMapper curingEmperatureMapper;

    @Override
    public Long createCuringEmperature(CuringEmperatureSaveReqVO createReqVO) {
        // 插入
        CuringEmperatureDO curingEmperature = BeanUtils.toBean(createReqVO, CuringEmperatureDO.class);
        curingEmperatureMapper.insert(curingEmperature);
        // 返回
        return curingEmperature.getId();
    }

    @Override
    public void updateCuringEmperature(CuringEmperatureSaveReqVO updateReqVO) {
        // 校验存在
        validateCuringEmperatureExists(updateReqVO.getId());
        // 更新
        CuringEmperatureDO updateObj = BeanUtils.toBean(updateReqVO, CuringEmperatureDO.class);
        curingEmperatureMapper.updateById(updateObj);
    }

    @Override
    public void deleteCuringEmperature(Long id) {
        // 校验存在
        validateCuringEmperatureExists(id);
        // 删除
        curingEmperatureMapper.deleteById(id);
    }

    @Override
        public void deleteCuringEmperatureListByIds(List<Long> ids) {
        // 校验存在
        validateCuringEmperatureExists(ids);
        // 删除
        curingEmperatureMapper.deleteByIds(ids);
        }

    private void validateCuringEmperatureExists(List<Long> ids) {
        List<CuringEmperatureDO> list = curingEmperatureMapper.selectByIds(ids);
        if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
            throw exception(CURING_EMPERATURE_NOT_EXISTS);
        }
    }

    private void validateCuringEmperatureExists(Long id) {
        if (curingEmperatureMapper.selectById(id) == null) {
            throw exception(CURING_EMPERATURE_NOT_EXISTS);
        }
    }

    @Override
    public CuringEmperatureDO getCuringEmperature(Long id) {
        return curingEmperatureMapper.selectById(id);
    }

    @Override
    public PageResult<CuringEmperatureDO> getCuringEmperaturePage(CuringEmperaturePageReqVO pageReqVO) {
        return curingEmperatureMapper.selectPage(pageReqVO);
    }

}